var cut[Nstate,Ncat-1];

model {
  for (i in 1:N){
    y[i] ~ dnorm(mu[i], 1)
    mu[i] <- b.state[stateID[i]] + b.1*chgUnemp1211[i] + b.2*avgUnemp12[i] + b.3*younger30[i]+  b.4*older65[i] + b.5*female[i] + b.6*black[i] + b.7*latino[i] + b.8*noHighSchool[i] + b.9*HighSchool[i] + b.10*someCollege[i] + b.11*fourCollege[i] + b.12*income[i] + b.13*unemployed[i] + b.14*fullTime[i] + b.15*partTime[i] + b.16*ownHome[i] + b.17*newsInt[i] + b.18*ideol[i] + b.19*Dem[i] + b.20*Rep[i] + b.21*Ind[i]
    for (k in 1:(Ncat-1)) { logit(Q[i,k]) <- cut[stateID[i], k] - mu[i]}
    p[i, 1] <- Q[i,1]
    for (k in 2:(Ncat-1)){ p[i,k] <- Q[i,k] - Q[i, (k-1)]}
    p[i, Ncat] <- 1 - Q[i, (Ncat-1)]
  }
  for (j in 1:Nstate){
    b.state[j] ~ dnorm(mu.state, tau.state)
  }
  mu.state ~ dnorm(0, 0.0001)
  tau.state <- pow(sigma.state, -2)
  sigma.state ~ dunif(0, 1000)
  b.1 ~ dnorm(0, 0.0001)
  b.2 ~ dnorm(0, 0.0001)
  b.3 ~ dnorm(0, 0.0001)
  b.4 ~ dnorm(0, 0.0001)
  b.5 ~ dnorm(0, 0.0001)
  b.6 ~ dnorm(0, 0.0001)
  b.7 ~ dnorm(0, 0.0001)
  b.8 ~ dnorm(0, 0.0001)
  b.9 ~ dnorm(0, 0.0001)
  b.10 ~ dnorm(0, 0.0001)
  b.11 ~ dnorm(0, 0.0001)
  b.12 ~ dnorm(0, 0.0001)
  b.13 ~ dnorm(0, 0.0001)
  b.14 ~ dnorm(0, 0.0001)
  b.15 ~ dnorm(0, 0.0001)
  b.16 ~ dnorm(0, 0.0001)
  b.17 ~ dnorm(0, 0.0001)
  b.18 ~ dnorm(0, 0.0001)
  b.19 ~ dnorm(0, 0.0001)
  b.20 ~ dnorm(0, 0.0001)
  b.21 ~ dnorm(0, 0.0001)

  for (j in 1:(Nstate)){
    for (k in 1: (Ncat-1)){
      cut0[j,k] ~ dt(0, 1, 5)
    }
    cut[j,] <- sort(cut0[j,])
  }
}